package com.ruoyi.system.service.impl;

import java.util.List;
import java.util.ArrayList;
import com.ruoyi.common.core.domain.Ztree;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.ServerTypeMapper;
import com.ruoyi.system.domain.ServerType;
import com.ruoyi.system.service.IServerTypeService;
import com.ruoyi.common.core.text.Convert;

/**
 * 服务分类Service业务层处理
 * 
 * @author ruoyi
 * @date 2021-11-13
 */
@Service("server")
public class ServerTypeServiceImpl implements IServerTypeService 
{
    @Autowired
    private ServerTypeMapper serverTypeMapper;

    /**
     * 查询服务分类
     * 
     * @param id 服务分类主键
     * @return 服务分类
     */
    @Override
    public ServerType selectServerTypeById(Long id)
    {
        return serverTypeMapper.selectServerTypeById(id);
    }

    /**
     * 查询服务分类列表
     * 
     * @param serverType 服务分类
     * @return 服务分类
     */
    @Override
    public List<ServerType> selectServerTypeList(ServerType serverType)
    {
        return serverTypeMapper.selectServerTypeList(serverType);
    }

    /**
     * 新增服务分类
     * 
     * @param serverType 服务分类
     * @return 结果
     */
    @Override
    public int insertServerType(ServerType serverType)
    {
        return serverTypeMapper.insertServerType(serverType);
    }

    /**
     * 修改服务分类
     * 
     * @param serverType 服务分类
     * @return 结果
     */
    @Override
    public int updateServerType(ServerType serverType)
    {
        return serverTypeMapper.updateServerType(serverType);
    }

    /**
     * 批量删除服务分类
     * 
     * @param ids 需要删除的服务分类主键
     * @return 结果
     */
    @Override
    public int deleteServerTypeByIds(String ids)
    {
        return serverTypeMapper.deleteServerTypeByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除服务分类信息
     * 
     * @param id 服务分类主键
     * @return 结果
     */
    @Override
    public int deleteServerTypeById(Long id)
    {
        return serverTypeMapper.deleteServerTypeById(id);
    }

    @Override
    public Long selectIdByName(String Name) {
        return serverTypeMapper.selectIdByName(Name);
    }

    /**
     * 服务下拉查询
     * @return
     */
    @Override
    public List<ServerType> selectServerTypeList() {
        ServerType serverType = new ServerType();
        serverType.setParentid(0L);
        return selectServerTypeList(serverType);
    }
    /**
     * 查询服务分类树列表
     * 
     * @return 所有服务分类信息
     */
    @Override
    public List<Ztree> selectServerTypeTree()
    {
        List<ServerType> serverTypeList = serverTypeMapper.selectServerTypeList(new ServerType());
        List<Ztree> ztrees = new ArrayList<Ztree>();
        for (ServerType serverType : serverTypeList)
        {
            Ztree ztree = new Ztree();
            ztree.setId(serverType.getId());
            ztree.setpId(serverType.getParentid());
            ztree.setName(serverType.getCName());
            ztree.setTitle(serverType.getCName());
            ztrees.add(ztree);
        }
        return ztrees;
    }
}
